home *** CD-ROM | disk | FTP | other *** search
- /*
- Commodore 64 Emulator v0.4 Earle F. Philhower III
- Copyright (C) 1993-4 (st916w9r@dunx1.ocs.drexel.edu)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #include "Processor.h"
- #include "Menus.h"
- #include "Error.h"
- #include "Resources.h"
-
- Handle menuBar;
- MenuHandle appleMenu, fileMenu, editMenu, deviceMenu;
- extern int programMode;
-
- int MenuInitialize()
- {
- menuBar=GetNewMBar(128);
- if (menuBar==nil) return kMissingResource;
- SetMenuBar(menuBar);
-
- appleMenu=GetMenu(kAppleMenu);
- if (appleMenu==nil) return kMissingResource;
- AddResMenu(appleMenu, 'DRVR');
-
- fileMenu=GetMenu(kFileMenu);
- if (fileMenu==nil) return kMissingResource;
- editMenu=GetMenu(kEditMenu);
- if (editMenu==nil) return kMissingResource;
- deviceMenu=GetMenu(kDeviceMenu);
- if (deviceMenu==nil) return kMissingResource;
-
- DisableItem(editMenu, 1);
- DrawMenuBar();
-
- return kNoError;
- }
-
-
- void DoMenuChoice(long menuChoice)
- {
- int theMenu, theItem;
-
- if (menuChoice==0)
- {
- HiliteMenu(0);
- return;
- }
-
- theMenu=HiWord(menuChoice);
- theItem=LoWord(menuChoice);
-
- HiliteMenu(theMenu);
-
- switch(theMenu)
- {
- case kAppleMenu:
- DoAppleMenu(theItem);
- break;
-
- case kFileMenu:
- DoFileMenu(theItem);
- break;
-
- case kEditMenu:
- DoEditMenu(theItem);
- break;
-
- case kDeviceMenu:
- DoDeviceMenu(theItem);
- break;
- }
-
- HiliteMenu(0);
- }
-
-
- void DoAppleMenu(int theItem)
- {
- EventRecord event;
- Str255 daName;
- DialogPtr dialog;
- WindowPtr theWind;
- int done;
-
- switch (theItem)
- {
- case kAbout:
- /* Show About... window */
- /* Don't draw it since MacOS will give us an update event */
- dialog=GetNewDialog(kAboutDialog, nil, (WindowPtr)-1L);
- SetWRefCon(dialog, kAboutWindow);
- ShowWindow(dialog);
-
- /* Handle events until time to drop window */
- done=0;
- while (!done)
- {
- WaitNextEvent(everyEvent, &event, 60L, nil);
- switch(event.what)
- {
- case mouseDown:
- case autoKey:
- case keyDown:
- /* On keypress or buttonpress stop waiting */
- done=1;
- break;
-
- case updateEvt:
- theWind=(WindowPtr)event.message;
- BeginUpdate(theWind);
- switch (GetWRefCon(theWind))
- {
- case kVICWindow:
- RedrawVIC();
- break;
- case kDirWindow:
- RedrawDir();
- break;
- case kAboutWindow:
- DrawDialog(dialog);
- break;
- }
- EndUpdate(theWind);
- break;
- }
- }
-
- /* Drop window and redraw the VIC screen */
- HideWindow(dialog);
- DisposDialog(dialog);
- TotalRedrawVIC();
- break;
-
- default:
- /* Run the selected Desk Accessory */
- GetItem(appleMenu, theItem, daName);
- OpenDeskAcc(daName);
- break;
- }
- }
-
-
- void DoFileMenu(int theItem)
- {
- switch(theItem)
- {
- case kOpenRAM:
- LoadRAM();
- break;
-
- case kSaveRAM:
- SaveRAM();
- break;
-
- case kReset:
- /* Clear the menu hilite, since we're gonna be away a while */
- HiliteMenu(0);
- /* Reset PC, memory map */
- RegisterInitialize();
- /* Go compute */
- if (programMode!=kRunning) ProcessorLoop();
- break;
-
- case kPageSetup:
- break;
-
- case kPrint:
- break;
-
- case kPrefs:
- DoPrefs();
- break;
-
- case kQuit:
- CleanUpCommodore();
- ExitToShell();
- break;
- }
- }
-
-
- void DoEditMenu(int theItem)
- {
- switch(theItem)
- {
- case kUndo:
- break;
-
- case kCut:
- break;
-
- case kCopy:
- break;
-
- case kPaste:
- break;
-
- case kClear:
- break;
- }
- }
-
-
- void DoDeviceMenu(int theItem)
- {
- switch(theItem)
- {
- case kCreateImage:
- FloppyCreateImage();
- break;
-
- case kSelectImage:
- FloppySelectImage();
- break;
-
- case kDirectory:
- FloppyDirectory();
- break;
-
- case kCopyTo:
- FloppyCopyTo();
- break;
-
- case kChdir:
- HardChangeDirectory();
- break;
-
- case kNewPFile:
- PrinterNewFile();
- break;
-
- case kAppendPFile:
- PrinterAppendFile();
- break;
-
- case kXvert:
- PrinterXvertCharacters();
- break;
-
- case kDisplayPFile:
- PrinterDisplayFile();
- break;
-
- case kLoadTape:
- LoadTape();
- break;
- }
- }
-